package com.cl.short_video_java.web.client.user;

import com.alipay.api.domain.UserDTO;
import com.cl.short_video_java.annotation.Login;
import com.cl.short_video_java.common.Const;
import com.cl.short_video_java.common.Result;
import com.cl.short_video_java.dto.UserDto;
import com.cl.short_video_java.pojo.VideoUser;
import com.cl.short_video_java.service.VideoUserService;
import com.cl.short_video_java.vo.user.FindPass;
import org.modelmapper.ModelMapper;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author 付
 * @Date 2024-11-24 16:02
 * @Version 1.0
 * @description
 * @since 1.0
 */

@RestController
@RequestMapping("/client/user")
public class ClientUserController {

	private VideoUserService userService;
	private ModelMapper modelMapper;

	public ClientUserController(VideoUserService userService, ModelMapper modelMapper) {
		this.userService = userService;
		this.modelMapper = modelMapper;
	}

	@GetMapping("/info")
	public Result info(@RequestParam("uid") Integer uid) {
		VideoUser info = userService.info(uid);
		return Result.success(info);
	}

	@GetMapping("/current")
	public Result current(HttpServletRequest request) {
		VideoUser user = userService.getCurrentUser(request, Const.GRADE_USER);
		UserDto map = modelMapper.map(user, UserDto.class);
		return Result.success(map);
	}

	@PostMapping("/find-pass")
	public Result findPass(@Validated @RequestBody FindPass findPass) {
		userService.findPass(findPass);
		return Result.success();
	}

	@GetMapping("/bind-email")
	@Login(issuer = Const.GRADE_USER)
	public Result bindEmail(@RequestParam("email") String email, @RequestParam("code") String code, HttpServletRequest request) {
		VideoUser user = userService.getCurrentUser(request, Const.GRADE_USER);
		userService.bindEmail(email, code, user);
		return Result.success();
	}


}
